<template>
  <div class="love-master">
    <!-- 背景效果 -->
    <div class="love-bg">
      <div class="gradient-overlay"></div>
      <div class="particles-container"></div>
      <div class="floating-hearts"></div>
      <div class="tech-grid"></div>
    </div>
    
    <!-- 侧边栏 -->
    <div class="sidebar" :class="{ 'collapsed': sidebarCollapsed }">
      <div class="sidebar-header">
        <div class="logo-container">
          <div class="logo-heart">
            <span>❤️</span>
            <div class="pulse-ring"></div>
          </div>
          <h2>AI 恋爱大师</h2>
        </div>
        <button class="collapse-btn" @click="toggleSidebar">
          {{ sidebarCollapsed ? '>' : '<' }}
        </button>
      </div>
      
      <div class="sidebar-content">
        <button class="new-chat-btn" @click="createNewChat">
          <span class="icon">+</span> 新建会话
          <div class="btn-glow"></div>
        </button>
        
        <div class="chat-list">
          <div 
            v-for="(chat, index) in chatHistory" 
            :key="chat.id" 
            :class="['chat-item', { active: activeChat === chat.id }]"
            @click="switchChat(chat.id)"
          >
            <div class="chat-info">
              <span class="chat-title">会话 {{ index + 1 }}</span>
              <span class="chat-date">{{ chat.date }}</span>
            </div>
            <button class="delete-chat-btn" @click.stop="deleteChat(chat.id)">×</button>
            <div class="item-highlight"></div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 侧边栏折叠时的展开按钮 -->
    <div class="expand-sidebar-btn" v-if="sidebarCollapsed" @click="toggleSidebar">
      <span>&raquo;</span>
      <div class="btn-pulse"></div>
    </div>
    
    <!-- 主内容区 -->
    <div class="main-content">
      <div class="header">
        <div class="back-button" @click="goBack">
          <span>&larr; 返回主页</span>
        </div>
        <div class="title">
          <span class="title-text">AI 恋爱大师</span>
          <div class="title-decoration"></div>
          <span v-if="chatId" class="chat-id-label">会话ID: {{ chatId }}</span>
        </div>
      </div>
      
      <div class="chat-container">
        <div class="chat-messages" ref="messagesContainer">
          <div v-if="messages.length === 0" class="welcome-message">
            <div class="welcome-icon">
              <div class="heart-container">
                <div class="heart"></div>
                <div class="heart-pulse"></div>
              </div>
            </div>
            <h3>欢迎使用 AI 恋爱大师</h3>
            <p>告诉我你的恋爱问题，获取专业建议</p>
          </div>
          <div v-for="(message, index) in messages" :key="index" 
               :class="['message', message.type === 'user' ? 'user-message' : 'ai-message']">
            <div class="message-content">
              <div class="message-text">{{ message.content }}</div>
              <div class="message-time">{{ message.time }}</div>
              <div class="tech-dots" v-if="message.type === 'ai'"></div>
            </div>
          </div>
        </div>
        
        <div class="chat-input">
          <input 
            type="text" 
            v-model="userInput" 
            @keyup.enter="sendMessage" 
            placeholder="请输入消息..." 
            :disabled="loading"
          />
          <button @click="sendMessage" :disabled="loading || !userInput.trim()">
            发送
            <div class="btn-glow"></div>
          </button>
        </div>
      </div>
      
      <!-- 装饰元素 -->
      <div class="corner-decoration top-right"></div>
      <div class="corner-decoration bottom-left"></div>
    </div>
  </div>
</template>

<script>
import { v4 as uuidv4 } from 'uuid'
import { chatWithLoveAppSse } from '@/services/api'

export default {
  name: 'LoveMasterView',
  data() {
    return {
      chatId: '',
      currentActiveChatId: '', // 专门用于高亮显示的ID
      eventSource: null,
      currentStreamingContent: '',
      userInput: '',
      messages: [],
      loading: false,
      currentStreamingMessageIndex: -1,
      sidebarCollapsed: false,
      chatHistory: [] // 存储会话历史
    }
  },
  computed: {
    // 通过计算属性确保高亮状态正确
    activeChat() {
      // 直接返回当前活动ID
      return this.currentActiveChatId;
    }
  },
  methods: {
    goBack() {
      this.$router.push('/')
    },
    
    toggleSidebar() {
      this.sidebarCollapsed = !this.sidebarCollapsed;
    },
    
    createNewChat() {
      // 如果当前有会话，先保存到历史中
      if (this.chatId) {
        this.saveChatToHistory();
      }
      
      // 创建新会话
      const newId = uuidv4();
      
      // 立即更新两个ID，确保视图更新
      this.chatId = newId;
      this.currentActiveChatId = newId;
      
      // 重置状态
      this.messages = [];
      this.userInput = '';
      this.loading = false;
      
      // 把新会话添加到历史
      this.chatHistory.unshift({
        id: newId,
        date: new Date().toLocaleString(),
        messages: []
      });
      
      // 强制刷新视图
      this.$forceUpdate();
    },
    
    switchChat(id) {
      // 防止重复点击相同会话
      if (this.chatId === id && this.currentActiveChatId === id) {
        return;
      }
      
      // 立即更新当前活动ID以确保高亮正确
      this.currentActiveChatId = id;
      
      // 首先保存当前会话的状态
      if (this.chatId && this.chatId !== id) {
        this.saveChatToHistory();
      }
      
      // 设置chatId
      this.chatId = id;
      
      // 查找并立即加载会话内容
      const chat = this.chatHistory.find(c => c.id === id);
      if (chat) {
        // 使用深拷贝避免引用问题
        this.messages = JSON.parse(JSON.stringify(chat.messages));
      } else {
        this.messages = [];
      }
      
      // 强制立即刷新DOM
      this.$forceUpdate();
      
      // 等待DOM更新后滚动到底部
      this.$nextTick(() => {
        this.scrollToBottom();
      });
    },
    
    deleteChat(id) {
      // 从历史中删除会话
      const index = this.chatHistory.findIndex(chat => chat.id === id);
      if (index !== -1) {
        this.chatHistory.splice(index, 1);
      }
      
      // 如果删除的是当前会话，创建新的或切换到另一个
      if (id === this.chatId) {
        if (this.chatHistory.length > 0) {
          this.switchChat(this.chatHistory[0].id);
        } else {
          this.createNewChat();
        }
      } else {
        // 即使不是当前会话，也需要强制刷新视图
        this.$forceUpdate();
      }
    },
    
    saveChatToHistory() {
      if (!this.chatId) return; // 如果没有chatId，不做任何操作
      
      const index = this.chatHistory.findIndex(chat => chat.id === this.chatId);
      if (index !== -1) {
        // 更新已有会话的消息
        this.chatHistory[index].messages = JSON.parse(JSON.stringify(this.messages)); // 深拷贝以避免引用问题
        
        // 如果有消息，则将会话移到最前面
        if (this.messages.length > 0) {
          const chat = this.chatHistory.splice(index, 1)[0];
          this.chatHistory.unshift(chat);
        }
      } else if (this.messages.length > 0) {
        // 只有当有消息时才添加新会话到历史
        this.chatHistory.unshift({
          id: this.chatId,
          date: new Date().toLocaleString(),
          messages: JSON.parse(JSON.stringify(this.messages)) // 深拷贝消息
        });
      }
    },
    
    sendMessage() {
      if (!this.userInput.trim() || this.loading) return;
      
      const userMessage = {
        content: this.userInput,
        type: 'user',
        time: new Date().toLocaleTimeString()
      };
      
      this.messages.push(userMessage);
      this.loading = true;
      
      // Store the current message
      const currentMessage = this.userInput;
      this.userInput = '';
      
      this.handleSendMessage(currentMessage);
    },
    
    handleSendMessage(message) {
      if (this.eventSource) {
        this.eventSource.close();
      }
      
      // Reset streaming content
      this.currentStreamingContent = '';
      
      // Add AI message placeholder that will be updated as content streams in
      this.startStreamingMessage();
      
      this.eventSource = chatWithLoveAppSse(message, this.chatId);
      
      this.eventSource.onmessage = (event) => {
        const data = event.data;
        if (data !== '[DONE]') {
          // Accumulate streaming content
          this.currentStreamingContent += data;
          // Update the current streaming message with new content
          this.updateStreamingMessage(this.currentStreamingContent);
        } else {
          // Finalize the message when stream is complete
          this.eventSource.close();
          this.eventSource = null;
          this.finishStreamingMessage();
          
          // 保存当前会话到历史
          this.saveChatToHistory();
        }
      };
      
      this.eventSource.onerror = (error) => {
        console.error('EventSource error:', error);
        this.eventSource.close();
        this.eventSource = null;
        this.finishStreamingMessage();
      };
    },
    
    // Start a new streaming AI message
    startStreamingMessage() {
      const aiMessage = {
        content: '',
        type: 'ai',
        time: new Date().toLocaleTimeString()
      }
      this.messages.push(aiMessage)
      this.currentStreamingMessageIndex = this.messages.length - 1
      this.loading = true
      this.scrollToBottom()
    },
    
    // Update the current streaming message with new content
    updateStreamingMessage(content) {
      if (this.currentStreamingMessageIndex >= 0) {
        this.messages[this.currentStreamingMessageIndex].content = content
        this.scrollToBottom()
      }
    },
    
    // Finish the streaming message and reset state
    finishStreamingMessage() {
      this.loading = false
      this.currentStreamingMessageIndex = -1
      this.scrollToBottom()
    },
    
    scrollToBottom() {
      this.$nextTick(() => {
        if (this.$refs.messagesContainer) {
          this.$refs.messagesContainer.scrollTop = this.$refs.messagesContainer.scrollHeight
        }
      })
    },
    
    // 创建背景粒子
    createParticles() {
      const container = document.querySelector('.particles-container');
      if (!container) return;
      
      const numberOfParticles = 50;
      
      for (let i = 0; i < numberOfParticles; i++) {
        const particle = document.createElement('div');
        particle.classList.add('bg-particle');
        
        // 随机属性
        const size = Math.random() * 3 + 1;
        const posX = Math.random() * 100;
        const posY = Math.random() * 100;
        const opacity = Math.random() * 0.3 + 0.1;
        const duration = Math.random() * 20 + 10;
        const delay = Math.random() * 10;
        
        particle.style.width = `${size}px`;
        particle.style.height = `${size}px`;
        particle.style.left = `${posX}%`;
        particle.style.top = `${posY}%`;
        particle.style.opacity = opacity;
        particle.style.animationDuration = `${duration}s`;
        particle.style.animationDelay = `${delay}s`;
        
        container.appendChild(particle);
      }
    },
    
    // 创建浮动的爱心
    createFloatingHearts() {
      const container = document.querySelector('.floating-hearts');
      if (!container) return;
      
      const numberOfHearts = 15;
      
      for (let i = 0; i < numberOfHearts; i++) {
        const heart = document.createElement('div');
        heart.classList.add('floating-heart');
        
        // 随机属性
        const size = Math.random() * 10 + 5;
        const posX = Math.random() * 100;
        const posY = Math.random() * 100;
        const opacity = Math.random() * 0.3 + 0.1;
        const duration = Math.random() * 30 + 20;
        const delay = Math.random() * 15;
        const scale = Math.random() * 0.5 + 0.5;
        
        heart.style.width = `${size}px`;
        heart.style.height = `${size}px`;
        heart.style.left = `${posX}%`;
        heart.style.bottom = `${posY}%`;
        heart.style.opacity = opacity;
        heart.style.animationDuration = `${duration}s`;
        heart.style.animationDelay = `${delay}s`;
        heart.style.transform = `scale(${scale})`;
        
        container.appendChild(heart);
      }
    },
    
    // 添加输入框焦点效果
    setupInputFocus() {
      const input = document.querySelector('.chat-input input');
      if (!input) return;
      
      input.addEventListener('focus', () => {
        input.parentNode.classList.add('input-focused');
      });
      
      input.addEventListener('blur', () => {
        input.parentNode.classList.remove('input-focused');
      });
    }
  },
  created() {
    // 初始化时不调用createNewChat，而是直接设置基本状态
    this.chatId = uuidv4();
    this.currentActiveChatId = this.chatId;
    
    // 创建初始会话
    this.chatHistory.unshift({
      id: this.chatId,
      date: new Date().toLocaleString(),
      messages: []
    });
  },
  beforeUnmount() {
    // Close the event source when the component is unmounted
    if (this.eventSource) {
      this.eventSource.close()
      this.eventSource = null
    }
  },
  mounted() {
    // 创建背景效果
    this.createParticles();
    this.createFloatingHearts();
    this.setupInputFocus();
    
    // 确保DOM挂载后强制更新一次视图
    this.$nextTick(() => {
      this.$forceUpdate();
    });
  }
}
</script>

<style scoped>
.love-master {
  display: flex;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: transparent;
}

/* 背景效果 */
.love-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
}

.gradient-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #ff3c7e 0%, #340847 100%);
  opacity: 0.85;
  z-index: 1;
}

.particles-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.floating-hearts {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.tech-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
                   linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.3;
  z-index: 2;
}

/* 装饰元素 */
.corner-decoration {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  z-index: 2;
  pointer-events: none;
}

.top-right {
  top: 20px;
  right: 20px;
  border-left: none;
  border-bottom: none;
}

.bottom-left {
  bottom: 20px;
  left: 20px;
  border-right: none;
  border-top: none;
}

/* 侧边栏样式 */
.sidebar {
  width: 280px;
  min-width: 280px;
  background-color: rgba(35, 0, 65, 0.7);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, min-width 0.3s ease;
  overflow: hidden;
  z-index: 10;
  flex-shrink: 0;
  backdrop-filter: blur(10px);
  position: relative;
  box-shadow: 5px 0 15px rgba(0, 0, 0, 0.2);
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header .logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-heart {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulse-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid rgba(255, 100, 200, 0.7);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.8);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.3;
  }
  100% {
    transform: scale(0.8);
    opacity: 0.8;
  }
}

.sidebar-header h2 {
  margin: 0;
  font-size: 18px;
  color: #fff;
  text-shadow: 0 0 10px rgba(255, 100, 200, 0.5);
}

.collapse-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.7);
  transition: all 0.3s ease;
}

.collapse-btn:hover {
  color: white;
  text-shadow: 0 0 10px rgba(255, 100, 200, 0.8);
}

/* 侧边栏折叠时的展开按钮 */
.expand-sidebar-btn {
  position: absolute;
  left: 0;
  top: 70px; /* 调整位置，避免遮挡返回按钮 */
  width: 24px;
  height: 48px;
  background-color: rgba(255, 0, 128, 0.7);
  color: white;
  border-radius: 0 4px 4px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  box-shadow: 2px 0 15px rgba(255, 0, 128, 0.4);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.expand-sidebar-btn:hover {
  background-color: rgba(255, 0, 128, 0.9);
  width: 30px;
}

.expand-sidebar-btn span {
  font-size: 18px;
  font-weight: bold;
  position: relative;
  z-index: 1;
}

.btn-pulse {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
  opacity: 0;
  animation: btn-pulse 2s infinite;
}

@keyframes btn-pulse {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
  }
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
}

.new-chat-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(45deg, #ff3b7e, #a239ca);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  font-weight: 500;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(255, 0, 128, 0.3);
}

.new-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 0, 128, 0.4);
}

.new-chat-btn .icon {
  margin-right: 8px;
  font-size: 18px;
}

.btn-glow {
  position: absolute;
  top: -50%;
  left: -100%;
  width: 200%;
  height: 200%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transform: rotate(45deg);
  animation: btn-glow 3s infinite;
  opacity: 0;
  transition: opacity 0.3s;
}

.new-chat-btn:hover .btn-glow {
  opacity: 1;
}

@keyframes btn-glow {
  0% {
    transform: rotate(45deg) translateX(-100%);
  }
  100% {
    transform: rotate(45deg) translateX(100%);
  }
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-item {
  padding: 12px;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-item:hover {
  background-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.chat-item.active {
  background-color: rgba(255, 100, 200, 0.2);
  border-left: 3px solid #ff3c7e;
}

.item-highlight {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  opacity: 0;
  transition: all 0.3s ease;
}

.chat-item:hover .item-highlight {
  opacity: 1;
}

.chat-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.chat-title {
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-date {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.delete-chat-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.7);
  padding: 0 5px;
  transition: all 0.2s ease;
}

.delete-chat-btn:hover {
  color: #ff3c7e;
  transform: scale(1.2);
}

/* 主内容区样式 */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0; /* 重要：允许容器缩小 */
  flex-grow: 1;
  position: relative;
  z-index: 5;
}

.header {
  padding: 15px 20px;
  background-color: rgba(35, 0, 65, 0.7);
  box-shadow: 0 1px 10px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.back-button {
  cursor: pointer;
  margin-right: 15px;
  padding: 6px 10px;
  border-radius: 4px;
  transition: all 0.3s ease;
  background-color: rgba(255, 255, 255, 0.1);
}

.back-button:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.back-button span {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 400;
  font-size: 14px;
}

.title {
  font-size: 18px;
  font-weight: 500;
  color: white;
  flex: 1;
  text-align: center;
  position: relative;
}

.title-text {
  background: linear-gradient(90deg, #ff3c7e, #a239ca);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255, 100, 200, 0.5);
}

.title-decoration {
  position: absolute;
  height: 2px;
  width: 50px;
  background: linear-gradient(90deg, transparent, #ff3c7e, transparent);
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
}

.chat-id-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  margin-left: 10px;
  font-weight: normal;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  background-color: rgba(20, 0, 40, 0.5);
  backdrop-filter: blur(5px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  background-color: transparent;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 100, 200, 0.5) rgba(35, 0, 65, 0.5);
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background-color: rgba(255, 100, 200, 0.5);
  border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-track {
  background-color: rgba(35, 0, 65, 0.5);
}

.welcome-message {
  text-align: center;
  margin: auto;
  padding: 30px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

.welcome-icon {
  margin-bottom: 20px;
}

.heart-container {
  width: 60px;
  height: 60px;
  position: relative;
  margin: 0 auto;
}

.heart {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  background: linear-gradient(45deg, #ff3c7e, #a239ca);
  border-radius: 50%;
  box-shadow: 0 0 30px rgba(255, 60, 126, 0.8);
}

.heart-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  border: 2px solid #ff3c7e;
  border-radius: 50%;
  animation: heart-pulse 2s infinite;
}

@keyframes heart-pulse {
  0% {
    width: 30px;
    height: 30px;
    opacity: 1;
  }
  100% {
    width: 60px;
    height: 60px;
    opacity: 0;
  }
}

.welcome-message h3 {
  margin: 10px 0;
  color: #ff3c7e;
  font-size: 20px;
  text-shadow: 0 0 10px rgba(255, 60, 126, 0.5);
}

.welcome-message p {
  color: rgba(255, 255, 255, 0.8);
}

.message {
  display: flex;
  margin-bottom: 10px;
  max-width: 85%;
}

.user-message {
  justify-content: flex-end;
  align-self: flex-end;
  padding-right: 15px;
}

.ai-message {
  justify-content: flex-start;
  align-self: flex-start;
  padding-left: 5px;
}

.message-content {
  padding: 12px 16px;
  border-radius: 18px;
  position: relative;
  word-break: break-word;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.user-message .message-content {
  background: linear-gradient(45deg, #ff3c7e, #a239ca);
  border-bottom-right-radius: 5px;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.ai-message .message-content {
  background-color: rgba(255, 255, 255, 0.1);
  border-bottom-left-radius: 5px;
  color: rgba(255, 255, 255, 0.9);
  border-left: 2px solid #ff3c7e;
  position: relative;
  backdrop-filter: blur(5px);
}

.tech-dots {
  position: absolute;
  bottom: 3px;
  left: 3px;
  width: 8px;
  height: 8px;
  background: #ff3c7e;
  border-radius: 50%;
  opacity: 0.6;
  animation: tech-dots-pulse 2s infinite;
}

@keyframes tech-dots-pulse {
  0% {
    transform: scale(0.8);
    opacity: 0.4;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.8;
  }
  100% {
    transform: scale(0.8);
    opacity: 0.4;
  }
}

.message-text {
  word-break: break-word;
  white-space: pre-wrap;
}

.message-time {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.6);
  text-align: right;
  margin-top: 5px;
}

.ai-message .message-time {
  color: rgba(255, 255, 255, 0.6);
}

.chat-input {
  display: flex;
  padding: 15px;
  background-color: rgba(35, 0, 65, 0.8);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

.chat-input input {
  flex: 1;
  padding: 12px 15px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  outline: none;
  margin-right: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  font-size: 16px;
  transition: all 0.3s ease;
}

.chat-input input:focus {
  border-color: #ff3c7e;
  box-shadow: 0 0 0 2px rgba(255, 60, 126, 0.2);
}

.chat-input input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.chat-input button {
  padding: 10px 20px;
  background: linear-gradient(135deg, #ff3c7e, #a239ca);
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.chat-input button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 60, 126, 0.4);
}

.chat-input button:disabled {
  background: linear-gradient(135deg, rgba(255, 60, 126, 0.5), rgba(162, 57, 202, 0.5));
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    height: 100%;
    z-index: 10;
  }
  
  .sidebar.collapsed {
    transform: translateX(-100%);
  }
  
  .main-content {
    width: 100%;
  }
}

/* 粒子和爱心效果 */
.bg-particle {
  position: absolute;
  background-color: #fff;
  border-radius: 50%;
  pointer-events: none;
  animation: float-particle linear infinite;
}

@keyframes float-particle {
  0% {
    transform: translateY(0) translateX(0);
  }
  25% {
    transform: translateY(-20px) translateX(10px);
  }
  50% {
    transform: translateY(0) translateX(20px);
  }
  75% {
    transform: translateY(20px) translateX(10px);
  }
  100% {
    transform: translateY(0) translateX(0);
  }
}

.floating-heart {
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: #ff3c7e;
  transform: rotate(45deg);
  pointer-events: none;
  animation: float-heart ease-in-out infinite;
}

.floating-heart::before,
.floating-heart::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: #ff3c7e;
  border-radius: 50%;
}

.floating-heart::before {
  top: -5px;
  left: 0;
}

.floating-heart::after {
  top: 0;
  left: -5px;
}

@keyframes float-heart {
  0% {
    transform: rotate(45deg) translateY(0) scale(1);
    opacity: 0.1;
  }
  50% {
    transform: rotate(45deg) translateY(-50px) scale(1.1);
    opacity: 0.3;
  }
  100% {
    transform: rotate(45deg) translateY(-100px) scale(0.8);
    opacity: 0;
  }
}

/* 输入框焦点效果 */
.chat-input.input-focused {
  box-shadow: 0 0 15px rgba(255, 60, 126, 0.3);
}

.chat-input.input-focused input {
  border-color: #ff3c7e;
  box-shadow: 0 0 0 2px rgba(255, 60, 126, 0.2);
}
</style> 